﻿<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>Web报表(B/S报表)演示 - 自定义报表导出行为，在事件中改变导出选项，调整默认导出行为</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<script src="../CreateControl.js" type="text/javascript"></script>
	<script type="text/javascript">
function window_onload() {
    ReportViewer.Report.OnExportBegin = OnExportBegin;
    ReportViewer.Report.OnExportEnd = OnExportEnd;

    ReportViewer.Start();
}

function OnExportBegin(OptionObject) 
{
    //ExportBegin 事件在将报表导出之前会触发到，无论是调用 ExportDirect 与 Export 方法，
    //还是从打印预览窗口等地方执行导出，都会触发到 ExportBegin 事件。
    //通常在 ExportBegin 事件中设置导出选项参数，改变默认导出行为

    var Report = ReportViewer.Report;
    
    OptionObject.AbortOpenFile = true;  //导出后不用关联程序打开导出文件，如导出Excel文件之后不用Excel打开
    OptionObject.AbortShowOptionDlg = false;  //导出之前不显示导出选项设置对话框

    //根据导出类型设置其特有的选项参数，有关选项参数的具体信息清参考帮助文档。
    //IGRExportOption是导出选项的基类，其它具体导出选项的接口名称都以IGRE2为前缀
    if (OptionObject.ExportType == 1) //gretXLS	
    {
        Report.DetailGrid.ColumnTitle.RepeatStyle = 1; //grrsNone
  
        OptionObject.FileName = "d:\\export\\gridreport.xls"; //指定导出文件的完整路径与文件名称
        
        var E2XLSOption = OptionObject.AsE2XLSOption;  //AsE2XLSOption是必须的
        E2XLSOption.OnlyExportDetailGrid = false;
        E2XLSOption.SupressEmptyLines = false;
        E2XLSOption.SameAsPrint = false; 
        E2XLSOption.ExportPageHeaderFooter = false; 
        E2XLSOption.ExportPageBreak = false; 
    }
    else if (OptionObject.ExportType == 2) //gretTXT	
    {
        OptionObject.FileName = "d:\\export\\gridreport.txt"; //指定导出文件的完整路径与文件名称
        
        var E2TXTOption = OptionObject.AsE2TXTOption;
        E2TXTOption.OnlyExportDetailGrid = false;
        E2TXTOption.SupressEmptyLines = false;
    }
    else if (OptionObject.ExportType == 3) //gretHTM	
    {
        OptionObject.FileName = "d:\\export\\gridreport.htm"; //指定导出文件的完整路径与文件名称
        
        var E2HTMOption = OptionObject.AsE2HTMOption;
        E2HTMOption.OnlyExportDetailGrid = false;
        E2HTMOption.SupressEmptyLines = false;
    }
    else if (OptionObject.ExportType == 4) //gretRTF	
    {
        OptionObject.FileName = "d:\\export\\gridreport.rtf"; //指定导出文件的完整路径与文件名称
        
        var E2RTFOption = OptionObject.AsE2RTFOption;
        E2RTFOption.OnlyExportDetailGrid = false;
        E2RTFOption.SupressEmptyLines = false;
    }
    else if (OptionObject.ExportType == 5) //gretPDF	
    {
        OptionObject.FileName = "d:\\export\\gridreport.pdf"; //指定导出文件的完整路径与文件名称
        
        var E2PDFOption = OptionObject.AsE2PDFOption;
        E2PDFOption.Author = "My Author";
        E2PDFOption.Subject = "My Subject";
    }
    else if (OptionObject.ExportType == 6) //gretCSV	
    {
        OptionObject.FileName = "d:\\export\\gridreport.csv"; //指定导出文件的完整路径与文件名称
        
        var E2CSVOption = OptionObject.AsE2CSVOption;
        E2CSVOption.OnlyExportDetailGrid = false;
        E2CSVOption.SupressEmptyLines = false;
    }
    else if (OptionObject.ExportType == 7) //gretIMG	
    {
        OptionObject.FileName = "d:\\export\\gridreport.png"; //指定导出文件的完整路径与文件名称
        
        var E2IMGOption = OptionObject.AsE2IMGOption;
        E2IMGOption.DPI = 300;
        E2IMGOption.ImageType = 2; //GRExportImageType.greitPNG
    }
}

function OnExportEnd(OptionObject)
{
    var Report = ReportViewer.Report;
    
    Report.DetailGrid.ColumnTitle.RepeatStyle = 2; //grrsOnPage
}
	</script>
    <style type="text/css">
        html,body {
            margin:0;
            height:100%;
        }
    </style>
</head>
<body style="margin:0" onload="window_onload()">
<script type="text/javascript"> 
    CreatePrintViewerEx("100%", "100%", "../../grf/1a.grf", "../../data/DataCenter.jsp?data=Customer", false, "");
    //CreateDisplayViewerEx("100%", "100%", "../../grf/1a.grf", "../../data/DataCenter.jsp?data=Customer", false, "<param name=BorderStyle value=0>");
</script>
</body>
</html>